package org.mybatis.plus.core;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Map;

import org.mybatis.plus.bean.Mapper;

public class SqlSession {

	private Connection connection;
	private  Map<String, Mapper> mapperMaps;

	public void setMapperMaps(Map<String, Mapper> mapperMaps) {
		this.mapperMaps = mapperMaps;
	}

	public  Map<String, Mapper>  getMapperMaps() {
		return mapperMaps;
	}

	public Connection getConnection() {
		return connection;
	}

	public SqlSession(Connection connection) {
		super();
		this.connection = connection;
	}
	
	public <T> T getMapper(Class<T> c) {
		SessionMapperProxy<T> mapperProxy = new SessionMapperProxy<T>();
		mapperProxy.setSqlSession(this);
		return (T) mapperProxy.getInstance(c);
	}

	public void commit() {
		try {
			System.out.println("commit==="+connection);
			connection.commit();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	public void rollback() {
		try {
			System.out.println("rollback==="+connection);
			connection.rollback();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public void close() {
		try {
			System.out.println("close==="+connection);
			connection.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
